<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/6/2
  Time: 10:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/wechat/order/emptyList.css">
    <link rel="stylesheet" href="/wechat/order/myList.css">
    <link rel="stylesheet" href="/wechat/order/myListModify.css">
    <jsp:include page="../public/head.jsp" flush="true" />
</head>
<body>
<jsp:include page="../public/header.jsp" flush="true" />
    <div class="home-nav-down">
        <table width="100%">
            <tbody><tr>
                <td class="last"><a href="/home/beforelogin/index.do?cityId=${rechargeCityId}" ><i class="iconfont ">&#xe612;</i>首页</a></td>
                <td><a class="current"><i class="iconfont icon-gouwuche">&#xe611;</i>订单</a></td>
                <td><a href="/ucenter/index.do" class="item bg5"><i class="iconfont icon-me">&#xe617;</i>我的</a></td>
            </tr>
            </tbody></table>
    </div>
    <c:choose>
        <c:when test="'+empty orders}">
            <section >
                <div class="pos_place"></div>
                <div class="tit">您没有下过订单呢，赶紧去您没有下过订单呢，赶紧去 下一单吧！</div>
                <a href="#" class="gobuy">去下一单</a>
            </section>
        </c:when>
        <c:otherwise>
            <section>
                <div class="my_list">
                    <div id="my_list"></div>
                    <div class="statusing" id="pullRefresh" hidden>正在加载...</div>
                </div>
                <!--/my_list -->
                </div>
            </section>
        </c:otherwise>
    </c:choose>
<script>

    var index = 0;
    var size = 5;
    var isLast = false;

    $(function () {
       update();
    });

    $(window).scroll(function() {
        var scrollTop = $(this).scrollTop();
        var scrollHeight = $(document).height();
        var windowHeight = $(this).height();
        if (scrollTop + windowHeight == scrollHeight) {
            if (!isLast){
                update();
            }
        }
    });

    function orderPay(orderNo) {
        <c:choose>
        <c:when test="${empty sessionScope.wxpay}">
            var http = "https://open.weixin.qq.com/connect/oauth2/authorize?";
            var appid = "&appid=wxf946190506655c2d";
            var redirect_uri = "&redirect_uri="+encodeURI("http://m.52letsgo.cn/order/orderPay.do");
            var response_type = "&response_type=code";
            var scope = "&scope=snsapi_base";
            var state = "&state="+orderNo;
            window.location.replace(http+appid+redirect_uri+response_type+scope+state+"#wechat_redirect");
        </c:when>
        <c:otherwise>
            window.location.replace("/order/orderPay.do?state="+orderNo);
        </c:otherwise>
        </c:choose>
    }

    function cancelOrder(id) {
        if (!confirm("是否删除订单")){
            return;
        }

        $.get("/mobile/user/order?action=delete&id="+id,function (data) {
            if (!data.success){
                tip("",data.msg,true);
            }else {
                window.location.reload();
            }
        },"json");
    }

    function update() {
        $("#pullRefresh").toggle();
        $.post("/mobile/user/order?action=list",{userId:${userinfo.id},begin:index,end:size},function (data) {
            if (!data.success){
                tip("",data.msg,true);
            }else {
                index = index+size;
                if (data.data.length > 0 ) {
                    $("#pullRefresh").toggle();
                    var html = "";
                    var length = 0;
                    $.each(data.data, function (i, item) {
                        switch (item.state) {
                            case 0:
                            {
                                html +=
                                        '<div class="status_list first">' +
                                        '   <div class="list-o">' +
                                        '   <div class="list-t">' +
                                        '   <div class="l-l">' +
                                        '   <span class="s1">下单时间:</span>' +
                                        '   <span class="s2">' + item.orderTime + '</span>' +
                                        '   </div>' +
                                        '   <div class="l-r">' +
                                        '   <span class="s3">待付款</span>' +
                                        '   <span class="s4">请在10分钟内完成订单</span>' +
                                        '   </div>' +
                                        '   </div>' +
                                        '   </div>';
                                for (var value in item.shopData) {
                                    $.each(item.shopData[value], function (j, child) {
                                        html +=
                                                '   <a href="/order/orderDetail.do?id=' + item.id + '">' +
                                                '   <div class="goodscont">' +
                                                '   <div class="goods_pic"><img src="' + child.productImage + '"></div>' +
                                                '   <div class="goods_name">' +
                                                '   <div class="txt1">' + child.productName + '</div>' +
                                                '   <div class="txt1">' + child.sendDate + '</div>' +
                                                '   <div class="txt1 txtprice">￥' + child.productPrice + '</div>' +
                                                '   <div class="txt1">X' + child.productCount + '</div>' +
                                                '   </div>' +
                                                '   </div>' +
                                                '   </a>';
                                        length++;
                                    });
                                }
                                html +=
                                        '    <div class="info">' +
                                        '   <div class="tip">共<span class="s1">' + length + '</span>件商品 总价:<span class="s1">￥' + item.totalPrice + '</span></div>' +
                                        '   <div class="opra">' +
                                        '   <input type="button" name="" class="btn1" value="取消订单" onclick="cancelOrder(\'' + item.id + '\')">' +
                                        '   <a onclick="orderPay(\'' + item.orderNo + '\')"><input type="button" name="" class="btn2" value="去付款" ></a>' +
                                        '   </div>' +
                                        '   </div>' +
                                        '   </div>';
                            }
                                break;
                            case 1:
                            {
                                html +=
                                        '<div class="status_list">' +
                                        '       <div class="list-o">' +
                                        '       <div class="list-t">' +
                                        '       <div class="l-l">' +
                                        '       <span class="s1">下单时间:</span>' +
                                        '<span class="s2">' + item.orderTime + '</span>' +
                                        '       </div>' +
                                        '       <div class="l-r">' +
                                        '       <span class="s5"> 未评价</span>' +
                                        '       </div>' +
                                        '       </div>' +
                                        '       </div>';
                                for (var value in item.shopData) {
                                    $.each(item.shopData[value], function (j, child) {
                                        html +=
                                                '   <a href="/order/orderDetail.do?id=' + item.id + '">' +
                                                '   <div class="goodscont">' +
                                                '   <div class="goods_pic"><img src="' + child.productImage + '"></div>' +
                                                '   <div class="goods_name">' +
                                                '   <div class="txt1">' + child.productName + '</div>' +
                                                '   <div class="txt1">配送时间:' + child.sendDate + '</div>' +
                                                '   <div class="txt1 txtprice">￥' + child.productPrice + '</div>' +
                                                '   <div class="txt1">X' + child.productCount + '</div>' +
                                                '   </div>' +
                                                '   </div>' +
                                                '   </a>';
                                        length++;
                                    });
                                }
                                html +=
                                        '       <div class="info">' +
                                        '       <div class="tip">共<span class="s1">' + length + '</span>件商品 总价:<span class="s1">￥' + item.totalPrice + '</span></div>' +
                                        '       <div class="opra">' +
                                        '       <a href="/order/orderComment.do?orderId=' + item.id + '"> <input type="button" name="" class="btn3" value="去评价"></a>' +
                                        '       </div>' +
                                        '       </div>' +
                                        '       </div>';
                            }
                                break;
                            case 2:
                            {
                                html +=
                                        '<div class="status_list">' +
                                        '       <div class="list-o">' +
                                        '       <div class="list-t">' +
                                        '       <div class="l-l">' +
                                        '       <span class="s1">下单时间:</span>' +
                                        '<span class="s2">' + item.orderTime + '</span>' +
                                        '       </div>' +
                                        '       <div class="l-r">' +
                                        '       <span class="s5">交易成功</span>' +
                                        '       </div>' +
                                        '       </div>' +
                                        '       </div>';
                                for (var value in item.shopData) {
                                    $.each(item.shopData[value], function (j, child) {
                                        html +=
                                                '   <a href="/order/orderDetail.do?id=' + item.id + '">' +
                                                '   <div class="goodscont">' +
                                                '   <div class="goods_pic"><img src="' + child.productImage + '"></div>' +
                                                '   <div class="goods_name">' +
                                                '   <div class="txt1">' + child.productName + '</div>' +
                                                '   <div class="txt1">配送时间:' + child.sendDate + '</div>' +
                                                '   <div class="txt1 txtprice">￥' + child.productPrice + '</div>' +
                                                '   <div class="txt1">X' + child.productCount + '</div>' +
                                                '   </div>' +
                                                '   </div>' +
                                                '   </a>';
                                        length++;
                                    });
                                }
                                html +=
                                        '       <div class="info">' +
                                        '       <div class="tip">共<span class="s1">' + length + '</span>件商品 总价:<span class="s1">￥' + item.totalPrice + '</span></div>' +
                                        '       <div class="opra">' +
                                        '       <a href="/order/orderComplaints.do?orderId=' + item.id + '"> <input type="button" name="" class="btn4" value="订单投诉"></a>' +
                                        '       </div>' +
                                        '       </div>' +
                                        '       </div>';
                            }
                                break;
                        }
                        length = 0;
                    });
                    $("#my_list").append(html);
                }else{
                    isLast = true;
                    $("#pullRefresh").text("已经加载全部");
                }
            }
        },"json");
    }
</script>
</body>
</html>
